{extends file="../home.html"}
{block name="title"}{$head_title}{/block}
{block name="css"}
<style>
	#map_container{
		width: 100%;
		height: 90%;
	}
	.service_header span{
		display:none;
	}
	.service_header p{
		width:80%;
		height:100%;
		overflow:hidden;
		text-overflow:ellipsis;
		white-space:nowrap;
		position: absolute;
		top:0;
		left:8%;
	}
</style>
{/block}
{block name="content"}
{include file="../common_header.html"}
<div class="map_container" id="map_container" style="margin-top: 15%"></div>
		
{/block}
{block name="js"}
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=BQLHGlffjbXC30bFDcpIQkHIkaxKBBe6"></script>
		<script>
		var s_lat = '{$lat}';
		var s_lng = '{$lng}';
		var lat,lng;
		var walking;
{literal}
		$('#mui-action-back').click(function(){
			history.go(-1);
		})
		var map_height=$(window).height();
		console.log(map_height);
		$('#map_container').css('height',map_height+'px');
		
		// 百度地图API功能
			var map = new BMap.Map("map_container");
			var point = new BMap.Point(s_lng, s_lat);
			map.centerAndZoom(point, 17);
			var marker = new BMap.Marker(point);  // 创建标注
			map.addOverlay(marker);      
		/*添加缩放控件*/
			var navControl = new BMap.NavigationControl({
				anchor: BMAP_ANCHOR_BOTTOM_RIGHT,
				type: 3
			});
			map.addControl(navControl);
			
		  // 添加定位控件
		  var geolocationControl = new BMap.GeolocationControl();
		  geolocationControl.addEventListener("locationSuccess", function(e){
		    // 定位成功事件
		    var address = '';
		    address += e.addressComponent.province;
		    address += e.addressComponent.city;
		    address += e.addressComponent.district;
		    address += e.addressComponent.street;
		    address += e.addressComponent.streetNumber;
		    // alert("当前定位地址为：" + address);
		  });
		  geolocationControl.addEventListener("locationError",function(e){
		    // 定位失败事件
		    alert(e.message);
		  });
		  map.addControl(geolocationControl);





			function gpslocation(){
				var geolocation = new BMap.Geolocation();
				geolocation.getCurrentPosition(function(r) {
					if(this.getStatus() == BMAP_STATUS_SUCCESS) {	
						//var myIcon = new BMap.Icon("__IMAGES__/front/icon_dwf.png", new BMap.Size(25,41));	
						//var mk = new BMap.Marker(r.point,{icon:myIcon});
						var mk = new BMap.Marker(r.point);
						mk.disableMassClear();
						map.addOverlay(mk);
						map.panTo(r.point);
						lat = r.point.lat;
						lng = r.point.lng;
						init();
						//console.log('您的位置：' + r.point.lng + ',' + r.point.lat);
						
						
						
					} else {
						alert('failed' + this.getStatus());
					}	
				}, {
					enableHighAccuracy: true
				});
			}
			$(function(){
				gpslocation();
			})
			function init(){
				walking = new BMap.WalkingRoute(map, {renderOptions:{map: map, autoViewport: true},onSearchComplete: searchComplete, onPolylinesSet: function(){//setTimeout(function(){alert(output)},"1000");
				}});
				walking.search(new BMap.Point(lng, lat), new BMap.Point(s_lng, s_lat));
			}
			//获取距离
			var searchComplete = function (results){
						if (walking.getStatus() != BMAP_STATUS_SUCCESS){
							return ;
						}
						var plan = results.getPlan(0);
						distance = plan.getDistance(true);
						$('.zuche > .zuche_title').find('span').html(distance);
			}

{/literal}
		</script>
{/block}
